Improve APIs for detecting the current country#597
Improve APIs for detecting the current country#597ccawley2011 wants to merge 1 commit intodevkitPro:masterfrom
Conversation
| CFG_COUNTRY_JO = 177, | ||
| CFG_COUNTRY_SM = 184, | ||
| CFG_COUNTRY_VA = 185, | ||
| CFG_COUNTRY_BM = 186, |
There was a problem hiding this comment.
There should be:
CFG_COUNTRY_OTHER = 254(used for some niche TWL stuff when restricting CTR country to TWL country enum)CFG_COUNTRY_OTHER = 255which can be returned byCFGU_GetCountryCodeID
| { | ||
| u8 unk[2]; | ||
| u8 state; | ||
| u8 country; |
| * @param string Pointer to output the string to. (must contain at least 2 bytes) | ||
| */ | ||
| Result CFGU_GetCountryCodeString(u16 code, u16* string); | ||
| Result CFGU_GetCountryCodeString(u16 code, char *string); |
There was a problem hiding this comment.
Actual type for the string is a NUL-terminated 2-char string (thus 3B in total). While char * is correct, a size hint wouldn't hurt; could you use char str[3] please?
Also, while inconsistent with the current rest-of-the-file, I would prefer (char outStr[3], CFG_Country code), likewise w/ the other functions you modified.
Corresponding decomp of the impl:
int __fastcall sub_108038(_DWORD *a1, unsigned int a2)
{
unsigned int v2; // r6
if ( a2 >= 0xBB )
{
strncpy(a1, (int *)dword_10D280, 3);
return 0xD90103FA;
}
v2 = a2;
strncpy(a1, (int *)dword_10D284[a2], 3);
if ( (unsigned int)sub_105D90((char *)dword_10D284[v2]) < 2 )
return 0xD90103FA;
return 0;
}| * @param code Pointer to output the country code to. (see @ref CFG_Country) | ||
| */ | ||
| Result CFGU_GetCountryCodeID(u16 string, u16* code); | ||
| Result CFGU_GetCountryCodeID(const char *string, u16* code); |
| * @brief Gets the system's country info. | ||
| * @param language Pointer to write the country info to. (see @ref CFG_CountryInfo) | ||
| */ | ||
| Result CFGU_GetSystemCountryInfo(CFG_CountryInfo* country); |
There was a problem hiding this comment.
cfguGetSystemCountryInfo since this is just a wrapper and not an actual IPC command
| } | ||
|
|
||
| Result CFGU_GetCountryCodeString(u16 code, u16* string) | ||
| Result CFGU_GetCountryCodeString(u16 code, char* string) |
| if(R_FAILED(ret = svcSendSyncRequest(cfguHandle)))return ret; | ||
|
|
||
| *string = (u16)cmdbuf[2] & 0xFFFF; | ||
| memcpy(string, &cmdbuf[2], 2); |
There was a problem hiding this comment.
2 -> 3 (or manually assign str[2] = '\0';)
| } | ||
|
|
||
| Result CFGU_GetCountryCodeID(u16 string, u16* code) | ||
| Result CFGU_GetCountryCodeID(const char* string, u16* code) |
|
|
||
| Result CFGU_GetSystemCountryInfo(CFG_CountryInfo* country) | ||
| { | ||
| return CFGU_GetConfigInfoBlk2(4, 0xB0000, country); |
There was a problem hiding this comment.
cfguGetSystemCountryInfo (and nit: wrong indentation here)
The
CFG_Countryenum was generated automatically using the linked test program: https://gist.github.com/ccawley2011/eb97f25dc09a50a9332dcced41d71858